

<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
  <meta charset="utf-8" />
  <meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />

  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  
  <title>crushtool -- CRUSH 图操作工具 &mdash; Ceph Documentation</title>
  

  
  <link rel="stylesheet" href="../../../_static/ceph.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/ceph.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/graphviz.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/css/custom.css" type="text/css" />

  
  

  
  

  

  
  <!--[if lt IE 9]>
    <script src="../../../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
        <script src="../../../_static/jquery.js"></script>
        <script src="../../../_static/_sphinx_javascript_frameworks_compat.js"></script>
        <script data-url_root="../../../" id="documentation_options" src="../../../_static/documentation_options.js"></script>
        <script src="../../../_static/doctools.js"></script>
        <script src="../../../_static/sphinx_highlight.js"></script>
    
    <script type="text/javascript" src="../../../_static/js/theme.js"></script>

    
    <link rel="index" title="Index" href="../../../genindex/" />
    <link rel="search" title="Search" href="../../../search/" />
    <link rel="next" title="librados-config -- 显示关于 librados 的信息" href="../librados-config/" />
    <link rel="prev" title="crushdiff -- ceph crush 图测试工具" href="../crushdiff/" /> 
</head>

<body class="wy-body-for-nav">

   
  <header class="top-bar">
    <div role="navigation" aria-label="Page navigation">
  <ul class="wy-breadcrumbs">
      <li><a href="../../../" class="icon icon-home" aria-label="Home"></a></li>
          <li class="breadcrumb-item"><a href="../../../rados/">Ceph 存储集群</a></li>
          <li class="breadcrumb-item"><a href="../../../rados/man/">对象存储手册页</a></li>
      <li class="breadcrumb-item active">crushtool -- CRUSH 图操作工具</li>
      <li class="wy-breadcrumbs-aside">
            <a href="../../../_sources/man/8/crushtool.rst.txt" rel="nofollow"> View page source</a>
      </li>
  </ul>
  <hr/>
</div>
  </header>
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search"  style="background: #eee" >
          

          
            <a href="../../../" class="icon icon-home"> Ceph
          

          
          </a>

          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../../search/" method="get">
    <input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        
        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../../../start/">Ceph 简介</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../install/">安装 Ceph</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../cephadm/">Cephadm</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../../../rados/">Ceph 存储集群</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../../../rados/configuration/">配置</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../../rados/operations/">运维</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="../../../rados/man/">    手册页</a><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="../ceph-volume/">ceph-volume -- Ceph OSD 部署和检查工具</a></li>
<li class="toctree-l3"><a class="reference internal" href="../ceph-volume-systemd/">ceph-volume-systemd -- systemd ceph-volume 辅助工具</a></li>
<li class="toctree-l3"><a class="reference internal" href="../ceph/">ceph -- Ceph 管理工具</a></li>
<li class="toctree-l3"><a class="reference internal" href="../ceph-authtool/">ceph-authtool -- ceph 密钥环操作工具</a></li>
<li class="toctree-l3"><a class="reference internal" href="../ceph-clsinfo/">ceph-clsinfo -- 查看类对象信息</a></li>
<li class="toctree-l3"><a class="reference internal" href="../ceph-conf/">ceph-conf -- ceph 配置文件工具</a></li>
<li class="toctree-l3"><a class="reference internal" href="../ceph-debugpack/">ceph-debugpack -- ceph 调试信息打包工具</a></li>
<li class="toctree-l3"><a class="reference internal" href="../ceph-dencoder/">ceph-dencoder -- ceph 编码器/解码器工具</a></li>
<li class="toctree-l3"><a class="reference internal" href="../ceph-mon/">ceph-mon -- ceph 监视器守护进程</a></li>
<li class="toctree-l3"><a class="reference internal" href="../ceph-osd/">ceph-osd -- ceph 对象存储守护进程</a></li>
<li class="toctree-l3"><a class="reference internal" href="../ceph-kvstore-tool/">ceph-kvstore-tool -- ceph 的 kvstore 操作工具</a></li>
<li class="toctree-l3"><a class="reference internal" href="../ceph-run/">ceph-run -- 发生核心转储后重启守护进程</a></li>
<li class="toctree-l3"><a class="reference internal" href="../ceph-syn/">ceph-syn -- ceph 的人造负载生成器</a></li>
<li class="toctree-l3"><a class="reference internal" href="../crushdiff/">crushdiff -- ceph crush 图测试工具</a></li>
<li class="toctree-l3 current"><a class="current reference internal" href="#">crushtool -- CRUSH 图操作工具</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#id1">提纲</a></li>
<li class="toctree-l4"><a class="reference internal" href="#id2">描述</a></li>
<li class="toctree-l4"><a class="reference internal" href="#test">用 --test 进行测试</a></li>
<li class="toctree-l4"><a class="reference internal" href="#build">用 <code class="docutils literal notranslate"><span class="pre">--build</span></code> 构建新图</a></li>
<li class="toctree-l4"><a class="reference internal" href="#id3">实例</a></li>
<li class="toctree-l4"><a class="reference internal" href="#id4">重新划类</a></li>
<li class="toctree-l4"><a class="reference internal" href="#id5"><code class="docutils literal notranslate"><span class="pre">--test</span></code> 的输出实例</a></li>
<li class="toctree-l4"><a class="reference internal" href="#id6">使用范围</a></li>
<li class="toctree-l4"><a class="reference internal" href="#id7">参考</a></li>
<li class="toctree-l4"><a class="reference internal" href="#id8">作者</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="../librados-config/">librados-config -- 显示关于 librados 的信息</a></li>
<li class="toctree-l3"><a class="reference internal" href="../monmaptool/">monmaptool -- ceph 监视器运行图操作工具</a></li>
<li class="toctree-l3"><a class="reference internal" href="../osdmaptool/">osdmaptool -- ceph osd 运行图操作工具</a></li>
<li class="toctree-l3"><a class="reference internal" href="../rados/">rados -- rados 对象存储工具</a></li>
<li class="toctree-l3"><a class="reference internal" href="../ceph-post-file/">ceph-post-file -- 把文件上传给 ceph 开发者</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../../rados/troubleshooting/">故障排除</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../../rados/api/">APIs</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../../cephfs/">Ceph 文件系统</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../rbd/">Ceph 块设备</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../radosgw/">Ceph 对象网关</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../mgr/">Ceph 管理器守护进程</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../mgr/dashboard/">Ceph 仪表盘</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../monitoring/">监控概览</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../api/">API 文档</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../architecture/">体系结构</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../dev/developer_guide/">开发者指南</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../dev/internals/">Ceph 内幕</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../governance/">项目管理</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../foundation/">Ceph 基金会</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../ceph-volume/">ceph-volume</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../releases/general/">Ceph 版本（总目录）</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../releases/">Ceph 版本（索引）</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../security/">Security</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../hardware-monitoring/">硬件监控</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../glossary/">Ceph 术语</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../jaegertracing/">Tracing</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../translation_cn/">中文版翻译资源</a></li>
</ul>

            
          
        </div>
        
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../../">Ceph</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
<div id="dev-warning" class="admonition note">
  <p class="first admonition-title">Notice</p>
  <p class="last">This document is for a development version of Ceph.</p>
</div>
  <div id="docubetter" align="right" style="padding: 5px; font-weight: bold;">
    <a href="https://pad.ceph.com/p/Report_Documentation_Bugs">Report a Documentation Bug</a>
  </div>

  
  <section id="crushtool-crush">
<h1>crushtool -- CRUSH 图操作工具<a class="headerlink" href="#crushtool-crush" title="Permalink to this heading"></a></h1>
<section id="id1">
<h2>提纲<a class="headerlink" href="#id1" title="Permalink to this heading"></a></h2>
<div class="line-block">
<div class="line"><strong>crushtool</strong> ( -d <em>map</em> | -c <em>map.txt</em> | --build --num_osds <em>numosds</em>
<em>layer1</em> <em>…</em> | --test ) [ -o <em>outfile</em> ]</div>
</div>
</section>
<section id="id2">
<h2>描述<a class="headerlink" href="#id2" title="Permalink to this heading"></a></h2>
<p><strong>crushtool</strong> 是 CRUSH 图处理工具，它允许你创建、编译、反编译和测试 CRUSH 图。</p>
<p>CRUSH 是个伪随机数据分布算法，它能高效地把输入值
（它在 Ceph 上下文中对应归置组）映射到异构、结构化的分级设备图中。
此算法最初是在下面的论文（虽说已改进过了）中详细描述的：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">http</span><span class="p">:</span><span class="o">//</span><span class="n">www</span><span class="o">.</span><span class="n">ssrc</span><span class="o">.</span><span class="n">ucsc</span><span class="o">.</span><span class="n">edu</span><span class="o">/</span><span class="n">Papers</span><span class="o">/</span><span class="n">weil</span><span class="o">-</span><span class="n">sc06</span><span class="o">.</span><span class="n">pdf</span>
</pre></div>
</div>
<p>此工具有四种操作模式。</p>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-crushtool-compile-c">
<span class="sig-name descname"><span class="pre">--compile|-c</span></span><span class="sig-prename descclassname"> <span class="pre">map.txt</span></span><a class="headerlink" href="#cmdoption-crushtool-compile-c" title="Permalink to this definition"></a></dt>
<dd><p>把纯文本 map.txt 编译为二进制图文件。</p>
</dd></dl>

<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-crushtool-decompile-d">
<span class="sig-name descname"><span class="pre">--decompile|-d</span></span><span class="sig-prename descclassname"> <span class="pre">map</span></span><a class="headerlink" href="#cmdoption-crushtool-decompile-d" title="Permalink to this definition"></a></dt>
<dd><p>接受已编译的图，
并把它反编译为适合编辑的纯文本源文件。</p>
</dd></dl>

<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-crushtool-build">
<span class="sig-name descname"><span class="pre">--build</span></span><span class="sig-prename descclassname"> <span class="pre">--num_osds</span> <span class="pre">{num-osds}</span> <span class="pre">layer1</span> <span class="pre">...</span></span><a class="headerlink" href="#cmdoption-crushtool-build" title="Permalink to this definition"></a></dt>
<dd><p>将用指定分级结构创建图。
详细解释见下文。</p>
</dd></dl>

<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-crushtool-test">
<span class="sig-name descname"><span class="pre">--test</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-crushtool-test" title="Permalink to this definition"></a></dt>
<dd><p>运行 CRUSH 模拟映射，参数是一系列输入值
<code class="docutils literal notranslate"><span class="pre">[--min-x,--max-x]</span></code> （默认是 <code class="docutils literal notranslate"><span class="pre">[0,1023]</span></code> ），
这个参数可当作是模拟的归置组。
详细解释见下文。</p>
</dd></dl>

<p>不像其它 Ceph 工具， <strong>crushtool</strong> 不接受命令行输入的像
<strong>--debug-crush</strong> 这样的通用选项；
却可以通过 CEPH_ARGS 环境变量提供。例如，
可以这样压制 CRUSH 子系统的所有输出：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">CEPH_ARGS</span><span class="o">=</span><span class="s2">&quot;--debug-crush 0&quot;</span> <span class="n">crushtool</span> <span class="o">...</span>
</pre></div>
</div>
</section>
<section id="test">
<h2>用 --test 进行测试<a class="headerlink" href="#test" title="Permalink to this heading"></a></h2>
<p>测试模式会采用输入 crush 图（用 <strong>-i map</strong> 指定的），
并模拟 CRUSH 映射或随机放置（若设置了 <strong>--simulate</strong> ）。
完成后可创建两种报告：
1) <strong>--show-…</strong> 选项会把人类可读的信息输出到标准错误；
2) <strong>--output-csv</strong> 选项会创建 CSV 文件，具体文档可在
<strong>--help-output</strong> 选项中见到。</p>
<p>注：每个归置组（ PG ）都有一个整数 ID ，可用 <code class="docutils literal notranslate"><span class="pre">ceph</span> <span class="pre">pg</span> <span class="pre">dump</span></code> 获取
（例如 PG 2.2f 意思是存储池 id 为 2 ， PG id 为 32）。
存储池和 PG 的 ID 用一个函数连结成一个值，
然后传递给 CRUSH 就可以映射到一组 OSD 。
crushtool 不知道什么是 PG 或存储池，
它只是对 <code class="docutils literal notranslate"><span class="pre">[--min-x,--max-x]</span></code> 范围内的取值进行模拟映射。</p>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-crushtool-show-statistics">
<span class="sig-name descname"><span class="pre">--show-statistics</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-crushtool-show-statistics" title="Permalink to this definition"></a></dt>
<dd><p>显示分布情况的摘要，例如：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">rule</span> <span class="mi">1</span> <span class="p">(</span><span class="n">metadata</span><span class="p">)</span> <span class="n">num_rep</span> <span class="mi">5</span> <span class="n">result</span> <span class="n">size</span> <span class="o">==</span> <span class="mi">5</span><span class="p">:</span>    <span class="mi">1024</span><span class="o">/</span><span class="mi">1024</span>
</pre></div>
</div>
<p>在如上输出中，规则 <strong>1</strong> 名字为 <strong>metadata</strong> ，
在试图把 <strong>1024</strong> 个值映射为 <strong>num_rep 5</strong> 个副本时，
最终成功地映射到了 <strong>result size == 5</strong> 个设备。
如果它最终没能输出映射，假设还需提高<strong>尝试</strong>次数），
就会显示失败情况。比如：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">rule</span> <span class="mi">1</span> <span class="p">(</span><span class="n">metadata</span><span class="p">)</span> <span class="n">num_rep</span> <span class="mi">10</span> <span class="n">result</span> <span class="n">size</span> <span class="o">==</span> <span class="mi">8</span><span class="p">:</span>   <span class="mi">4</span><span class="o">/</span><span class="mi">1024</span>
<span class="n">rule</span> <span class="mi">1</span> <span class="p">(</span><span class="n">metadata</span><span class="p">)</span> <span class="n">num_rep</span> <span class="mi">10</span> <span class="n">result</span> <span class="n">size</span> <span class="o">==</span> <span class="mi">9</span><span class="p">:</span>   <span class="mi">93</span><span class="o">/</span><span class="mi">1024</span>
<span class="n">rule</span> <span class="mi">1</span> <span class="p">(</span><span class="n">metadata</span><span class="p">)</span> <span class="n">num_rep</span> <span class="mi">10</span> <span class="n">result</span> <span class="n">size</span> <span class="o">==</span> <span class="mi">10</span><span class="p">:</span>  <span class="mi">927</span><span class="o">/</span><span class="mi">1024</span>
</pre></div>
</div>
<p>以上表明，虽然要求的副本数是 <strong>num_rep 10</strong> ，
但是 <strong>1024</strong> 个值中只有 <strong>4</strong> 个（ <strong>4/1024</strong> ）映射到了
<strong>result size == 8</strong> 个设备。</p>
</dd></dl>

<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-crushtool-show-mappings">
<span class="sig-name descname"><span class="pre">--show-mappings</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-crushtool-show-mappings" title="Permalink to this definition"></a></dt>
<dd><p>显示 <code class="docutils literal notranslate"><span class="pre">[--min-x,--max-x]</span></code> 范围内每个值的映射，
例如：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">CRUSH</span> <span class="n">rule</span> <span class="mi">1</span> <span class="n">x</span> <span class="mi">24</span> <span class="p">[</span><span class="mi">11</span><span class="p">,</span><span class="mi">6</span><span class="p">]</span>
</pre></div>
</div>
<p>显示了值 <strong>24</strong> 被规则 <strong>1</strong> 映射到了设备 <strong>[11,6]</strong> 。</p>
<p>使用 <code class="docutils literal notranslate"><span class="pre">--show-mappings</span></code> 选项时，必须加上下面之中的一个：</p>
<blockquote>
<div><ol class="loweralpha simple">
<li><p><code class="docutils literal notranslate"><span class="pre">--num-rep</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">--min-rep</span></code> 和 <code class="docutils literal notranslate"><span class="pre">--max-rep</span></code> 都加上</p></li>
</ol>
</div></blockquote>
<p><code class="docutils literal notranslate"><span class="pre">--num-rep</span></code> 意思是”副本数”，表示存储池内的副本数量。
表示存储池中的副本数量，并用于指定副本的精确数量
（例如 <code class="docutils literal notranslate"><span class="pre">--num-rep</span> <span class="pre">5</span></code> ）。 <code class="docutils literal notranslate"><span class="pre">--min-rep</span></code> 和 <code class="docutils literal notranslate"><span class="pre">--max-rep</span></code> 一并使用
可以指定副本数的范围（例如 <code class="docutils literal notranslate"><span class="pre">--min-rep</span> <span class="pre">1</span> <span class="pre">--max-rep</span> <span class="pre">10</span></code> ）。</p>
</dd></dl>

<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-crushtool-show-bad-mappings">
<span class="sig-name descname"><span class="pre">--show-bad-mappings</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-crushtool-show-bad-mappings" title="Permalink to this definition"></a></dt>
<dd><p>查看哪个值的映射数量没达到要求，
例如：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">bad</span> <span class="n">mapping</span> <span class="n">rule</span> <span class="mi">1</span> <span class="n">x</span> <span class="mi">781</span> <span class="n">num_rep</span> <span class="mi">7</span> <span class="n">result</span> <span class="p">[</span><span class="mi">8</span><span class="p">,</span><span class="mi">10</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">11</span><span class="p">,</span><span class="mi">6</span><span class="p">,</span><span class="mi">9</span><span class="p">]</span>
</pre></div>
</div>
<p>表明规则 <strong>1</strong> 要求映射到 <strong>7</strong> 个设备，实际上只映射了六个：
<strong>[8,10,2,11,6,9]</strong> 。</p>
</dd></dl>

<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-crushtool-show-utilization">
<span class="sig-name descname"><span class="pre">--show-utilization</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-crushtool-show-utilization" title="Permalink to this definition"></a></dt>
<dd><p>显示每个设备的期望和实际利用率，各种数量的副本也计算在内。例如：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">device</span> <span class="mi">0</span><span class="p">:</span> <span class="n">stored</span> <span class="p">:</span> <span class="mi">951</span>      <span class="n">expected</span> <span class="p">:</span> <span class="mf">853.333</span>
<span class="n">device</span> <span class="mi">1</span><span class="p">:</span> <span class="n">stored</span> <span class="p">:</span> <span class="mi">963</span>      <span class="n">expected</span> <span class="p">:</span> <span class="mf">853.333</span>
<span class="o">...</span>
</pre></div>
</div>
<p>表明设备 <strong>0</strong> 实际存储了 <strong>951</strong> 个值，本来期望存储 <strong>853</strong>
个。隐含了 <strong>--show-statistics</strong> 。</p>
</dd></dl>

<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-crushtool-show-utilization-all">
<span class="sig-name descname"><span class="pre">--show-utilization-all</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-crushtool-show-utilization-all" title="Permalink to this definition"></a></dt>
<dd><p>显示结果与 <strong>--show-utilization</strong> 相同，
只是不剔除权重为 0 的设备。
隐含了 <strong>--show-statistics</strong> 。</p>
</dd></dl>

<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-crushtool-show-choose-tries">
<span class="sig-name descname"><span class="pre">--show-choose-tries</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-crushtool-show-choose-tries" title="Permalink to this definition"></a></dt>
<dd><p>显示要尝试多少次才能映射到设备。例如：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="mi">0</span><span class="p">:</span>     <span class="mi">95224</span>
<span class="mi">1</span><span class="p">:</span>      <span class="mi">3745</span>
<span class="mi">2</span><span class="p">:</span>      <span class="mi">2225</span>
<span class="o">..</span>
</pre></div>
</div>
<p>表明有 <strong>95224</strong> 次映射没重试就成功了，
<strong>3745</strong> 次映射尝试一次后成功，等等。
显示的最大行数与 <strong>--set-choose-total-tries</strong> 选项相同。</p>
</dd></dl>

<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-crushtool-output-csv">
<span class="sig-name descname"><span class="pre">--output-csv</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-crushtool-output-csv" title="Permalink to this definition"></a></dt>
<dd><p>在当前目录内创建 CSV 文件用于保存输出信息，
具体请参考 <strong>--help-output</strong> 。
文件被命名为收集统计信息时涉及的规则，
比如使用了 metadata 规则时， CSV 文件将会是：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">metadata</span><span class="o">-</span><span class="n">absolute_weights</span><span class="o">.</span><span class="n">csv</span>
<span class="n">metadata</span><span class="o">-</span><span class="n">device_utilization</span><span class="o">.</span><span class="n">csv</span>
<span class="o">...</span>
</pre></div>
</div>
<p>文件的首行是本列的简单描述，例如：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">metadata</span><span class="o">-</span><span class="n">absolute_weights</span><span class="o">.</span><span class="n">csv</span>
<span class="n">Device</span> <span class="n">ID</span><span class="p">,</span> <span class="n">Absolute</span> <span class="n">Weight</span>
<span class="mi">0</span><span class="p">,</span><span class="mi">1</span>
<span class="o">...</span>
</pre></div>
</div>
</dd></dl>

<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-crushtool-output-name">
<span class="sig-name descname"><span class="pre">--output-name</span></span><span class="sig-prename descclassname"> <span class="pre">NAME</span></span><a class="headerlink" href="#cmdoption-crushtool-output-name" title="Permalink to this definition"></a></dt>
<dd><p>指定了 <strong>--output-csv</strong> 选项时生成的文件名要加
<strong>NAME</strong> 前缀，例如 <strong>--output-name FOO</strong> 将创建这些文件：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">FOO</span><span class="o">-</span><span class="n">metadata</span><span class="o">-</span><span class="n">absolute_weights</span><span class="o">.</span><span class="n">csv</span>
<span class="n">FOO</span><span class="o">-</span><span class="n">metadata</span><span class="o">-</span><span class="n">device_utilization</span><span class="o">.</span><span class="n">csv</span>
<span class="o">...</span>
</pre></div>
</div>
</dd></dl>

<p>用 <strong>--set-…</strong> 选项可修改指定 crush 图内的可调值，
输入的 crush 图在内存中修改了。
例如：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ crushtool -i mymap --test --show-bad-mappings
bad mapping rule 1 x 781 num_rep 7 result [8,10,2,11,6,9]
</pre></div>
</div>
<p>上面的问题可通过增加 <strong>choose-total-tries</strong> 来修正，如：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ crushtool -i mymap --test \
    --show-bad-mappings \
    --set-choose-total-tries 500
</pre></div>
</div>
</section>
<section id="build">
<h2>用 <code class="docutils literal notranslate"><span class="pre">--build</span></code> 构建新图<a class="headerlink" href="#build" title="Permalink to this heading"></a></h2>
<p>构建模式可生成一个分级图。
第一个参数指定了 CRUSH 分级结构中的设备（叶子）数量。
每一层都要描述如何分组前一层（或设备）。</p>
<p>各层都由如下要素组成：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">bucket</span> <span class="p">(</span> <span class="n">uniform</span> <span class="o">|</span> <span class="nb">list</span> <span class="o">|</span> <span class="n">tree</span> <span class="o">|</span> <span class="n">straw</span> <span class="o">|</span> <span class="n">straw2</span> <span class="p">)</span> <span class="n">size</span>
</pre></div>
</div>
<p>这里的 <strong>bucket</strong> 是本层桶的类型（如 “rack” ）。
构建时各桶名 <strong>bucket</strong> 后将追加一个惟一的数字
（如 “rack0” 、 “rack1” ……）。</p>
<p>第二个组件是桶类型：大多用 <strong>straw</strong> 。</p>
<p>第三个组件是此桶的最大尺寸，为零时表示容量无限。</p>
</section>
<section id="id3">
<h2>实例<a class="headerlink" href="#id3" title="Permalink to this heading"></a></h2>
<p>假设我们有 2 行、每行有 2 个机架、每机架有 20 个节点、
每个节点有 4 个存储设备用于 OSD 守护进程，
这样的配置允许部署 320 个 OSD 守护进程。这里按照机架高 42U ，
节点都是 2U 高的，另外空余 2U 装机架交换机。</p>
<p>要如实展现我们的设备、节点、机架、行构成的分级结构，用此命令：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ crushtool -o crushmap --build --num_osds 320 \
       node straw 4 \
       rack straw 20 \
       row straw 2 \
       root straw 0
# id        weight  type name       reweight
-87 320     root root
-85 160             row row0
-81 80                      rack rack0
-1  4                               node node0
0   1                                       osd.0   1
1   1                                       osd.1   1
2   1                                       osd.2   1
3   1                                       osd.3   1
-2  4                               node node1
4   1                                       osd.4   1
5   1                                       osd.5   1
...
</pre></div>
</div>
<p>这样就创建了 CRUSH 规则，以便测试。此规则与创建集群时默认创建的规则相同，
可用下面的方法编辑它们：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># 反编译</span>
<span class="n">crushtool</span> <span class="o">-</span><span class="n">d</span> <span class="n">crushmap</span> <span class="o">-</span><span class="n">o</span> <span class="nb">map</span><span class="o">.</span><span class="n">txt</span>

<span class="c1"># 编辑</span>
<span class="n">emacs</span> <span class="nb">map</span><span class="o">.</span><span class="n">txt</span>

<span class="c1"># 重新编译</span>
<span class="n">crushtool</span> <span class="o">-</span><span class="n">c</span> <span class="nb">map</span><span class="o">.</span><span class="n">txt</span> <span class="o">-</span><span class="n">o</span> <span class="n">crushmap</span>
</pre></div>
</div>
</section>
<section id="id4">
<h2>重新划类<a class="headerlink" href="#id4" title="Permalink to this heading"></a></h2>
<p><em>reclassify</em> 功能便于用户把较老的图
（维护着不同类型 OSD 的并行层次结构）转换为最新的 CRUSH 图，
这样才能用得上 <em>device class</em> 功能。更多信息见
<a class="reference external" href="https://docs.ceph.com/en/latest/rados/operations/crush-map-edits/#migrating-from-a-legacy-ssd-rule-to-device-classes">https://docs.ceph.com/en/latest/rados/operations/crush-map-edits/#migrating-from-a-legacy-ssd-rule-to-device-classes</a> 。</p>
</section>
<section id="id5">
<h2><code class="docutils literal notranslate"><span class="pre">--test</span></code> 的输出实例<a class="headerlink" href="#id5" title="Permalink to this heading"></a></h2>
<p>请到 <a class="reference external" href="https://github.com/ceph/ceph/blob/master/src/test/cli/crushtool/set-choose.t">https://github.com/ceph/ceph/blob/master/src/test/cli/crushtool/set-choose.t</a>
查看 <code class="docutils literal notranslate"><span class="pre">crushtool</span> <span class="pre">--test</span></code> 命令实例，及其输出。</p>
</section>
<section id="id6">
<h2>使用范围<a class="headerlink" href="#id6" title="Permalink to this heading"></a></h2>
<p><strong>crushtool</strong> 是 Ceph 的一部分，这是个伸缩力强、开源、分布式的存储系统，更多信息参见 <a class="reference external" href="https://docs.ceph.com">https://docs.ceph.com</a> 。</p>
</section>
<section id="id7">
<h2>参考<a class="headerlink" href="#id7" title="Permalink to this heading"></a></h2>
<p><a class="reference internal" href="../ceph/"><span class="doc">ceph</span></a>(8),
<a class="reference internal" href="../osdmaptool/"><span class="doc">osdmaptool</span></a>(8),</p>
</section>
<section id="id8">
<h2>作者<a class="headerlink" href="#id8" title="Permalink to this heading"></a></h2>
<p>John Wilkins 、 Sage Weil 、 Loic Dachary</p>
</section>
</section>



<div id="support-the-ceph-foundation" class="admonition note">
  <p class="first admonition-title">Brought to you by the Ceph Foundation</p>
  <p class="last">The Ceph Documentation is a community resource funded and hosted by the non-profit <a href="https://ceph.io/en/foundation/">Ceph Foundation</a>. If you would like to support this and our other efforts, please consider <a href="https://ceph.io/en/foundation/join/">joining now</a>.</p>
</div>


           </div>
           
          </div>
          <footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
        <a href="../crushdiff/" class="btn btn-neutral float-left" title="crushdiff -- ceph crush 图测试工具" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
        <a href="../librados-config/" class="btn btn-neutral float-right" title="librados-config -- 显示关于 librados 的信息" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
    </div>

  <hr/>

  <div role="contentinfo">
    <p>&#169; Copyright 2016, Ceph authors and contributors. Licensed under Creative Commons Attribution Share Alike 3.0 (CC-BY-SA-3.0).</p>
  </div>

   

</footer>
        </div>
      </div>

    </section>

  </div>
  

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>